public class PasswordManager {
    public static String encrypt(String password) {
        // 规则1：将每个字符的ASCII码加上它在字符串中的位置(从1开始)和偏移值3
        StringBuilder encryptedPassword = new StringBuilder();
        for (int i = 0; i < password.length(); i++) {
            char c = (char) (password.charAt(i) + i + 1 + 3);
            encryptedPassword.append(c);
        }

        // 规则2：将字符串的第一位和最后一位调换顺序
        if (encryptedPassword.length() >= 2) {
            char firstChar = encryptedPassword.charAt(0);
            char lastChar = encryptedPassword.charAt(encryptedPassword.length() - 1);
            encryptedPassword.setCharAt(0, lastChar);
            encryptedPassword.setCharAt(encryptedPassword.length() - 1, firstChar);
        }

        // 规则3：将字符串反转
        return encryptedPassword.reverse().toString();
    }

    public static String decrypt(String encryptedPassword) {
        // 规则3：将字符串反转
        StringBuilder decryptedPassword = new StringBuilder(encryptedPassword).reverse();

        // 规则2：将字符串的第一位和最后一位调换顺序
        if (decryptedPassword.length() >= 2) {
            char firstChar = decryptedPassword.charAt(0);
            char lastChar = decryptedPassword.charAt(decryptedPassword.length() - 1);
            decryptedPassword.setCharAt(0, lastChar);
            decryptedPassword.setCharAt(decryptedPassword.length() - 1, firstChar);
        }

        // 规则1：将每个字符的ASCII码减去它在字符串中的位置(从1开始)和偏移值3
        StringBuilder password = new StringBuilder();
        for (int i = 0; i < decryptedPassword.length(); i++) {
            char c = (char) (decryptedPassword.charAt(i) - i - 1 - 3);
            password.append(c);
        }

        return password.toString();
    }

    public static boolean checkStrength(String password) {
        // 判断密码强度
        // 这里可以根据你的规则进行判断，这里只是简单示例
        return password.length() >= 8;
    }

    public static String generatePassword() {
        // 生成随机密码
        // 这里只是简单示例，你可以根据规则编写更复杂的生成逻辑
        String characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        StringBuilder generatedPassword = new StringBuilder();
        for (int i = 0; i < 8; i++) {
            int randomIndex = (int) (Math.random() * characters.length());
            char c = characters.charAt(randomIndex);
            generatedPassword.append(c);
        }
        return generatedPassword.toString();
    }

    public static void main(String[] args) {
        // 使用示例
        String password = "dy610500947";

        String encryptedPassword = encrypt(password);
        System.out.println("加密密码: " + encryptedPassword);

        String decryptedPassword = decrypt(encryptedPassword);
        System.out.println("解密密码: " + decryptedPassword);

        boolean isStrong = checkStrength(password);
        System.out.println("密码强度: " + (isStrong ? "Strong" : "Weak"));

        String generatedPassword = generatePassword();
        System.out.println("生成的密码: " + generatedPassword);
    }
}